﻿using System.Threading.Tasks;
using AutoMapper;
using Domain.Entity.Dtos;
using Domain.Entity.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TestDDD.Services;

namespace TestDDD.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QueryController(IUserService userService, IMapper mapper) : ControllerBase
    {
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }

        [HttpPost]
        public async Task<User> AddUserAsnyc(UserDto userdto)
        {
            User user = mapper.Map<User>(userdto);
            return await userService.AddAsync(user);
        }

        [HttpPost]
        public User AddUser(UserDto userdto)
        {
            User user = mapper.Map<User>(userdto);
            return userService.Add(user);
        }

        [HttpPut("/{id}/{name}")]
        public async Task<bool> ChangeUserName(int id, string name)
        {
            return await userService.ChangeUserName(id, name);
        }
    }
}
